package com.ycy.listener;

import org.flowable.common.engine.api.delegate.event.FlowableEngineEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.common.engine.impl.cfg.TransactionState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TransactionCommittingFlowableListener implements FlowableEventListener {

  Logger logger = LoggerFactory.getLogger(this.getClass());

  @Override
  public void onEvent(FlowableEvent flowableEvent) {
    logger.info("COMMITTING 通知事件 --> {}", flowableEvent);

    if (flowableEvent instanceof FlowableEngineEvent) {
      FlowableEngineEvent event = (FlowableEngineEvent) flowableEvent;
      String procInstId = event.getProcessInstanceId();
      logger.info("COMMITTING 通知事件 --> procInstId：{}", procInstId);
    }

  }

  @Override
  public boolean isFailOnException() {
    return true;
  }

  @Override
  public boolean isFireOnTransactionLifecycleEvent() {
    return true;
  }

  @Override
  public String getOnTransaction() {
    return TransactionState.COMMITTING.name();
  }

}
